import { addr } from "./proto";

function main_err_info(ec: number) {
    switch (ec) {
        case 0x10: return '温控器读取超时';
        case 0x11: return '温控器数据异常';
        case 0x12: return '扫码枪读取超时';
        case 0x13: return '扫码枪数据异常';
        case 0x14: return '加热控制板通信失败';
        case 0x15: return '加热控制板通信异常';
        case 0x16: return '货架升降电机堵转';
        case 0x17: return '货架升降电机超时';
        case 0x18: return '货架旋转电机堵转';
        case 0x19: return '货架旋转电机超时';
        case 0x1A: return '保温门电机超时';
        case 0x1B: return '煮面室内门电机超时';
        case 0x1C: return '外推货电机堵转';
        case 0x1D: return '外推货电机超时';
        case 0x1E: return '取物门电机堵转';
        case 0x1F: return '取物门电机超时';
        case 0x20: return '取物门光栅被遮挡';
        case 0x21: return '取物门防夹手';
        case 0x22: return '取货电机堵转';
        case 0x23: return '取货电机超时';
        case 0x24: return '煮面室内有东西';
        case 0x25: return '取了个空的';
    }
    return `主控板未知错误:${ec}`;
}

function heat_err_info(ec: number) {
    switch (ec) {
        case 0x10: return '流量计异常';
        case 0x11: return '流量计超时';
        case 0x12: return '喷嘴电机堵转';
        case 0x13: return '喷嘴电机超时';
        case 0x14: return '温度传感器错误';
    }
    return `加热控制板未知错误:${ec}`;
}

function weight_err_info(ec: number) {
    switch (ec) {
        case 0x10: return '电子秤读取超时';
        case 0x11: return '校准失败';
    }
    return `称重控制板未知错误:${ec}`;
}

export function err_msg_info(src: number, ec: number) {

    if (ec < 0x10) {
        switch (ec) {
            case 0: return '正常';
            case 0x01: return '无效的参数';
            case 0x02: return '参数解析错误';
            case 0x03: return 'SESSION没有收到ACK';
            case 0x04: return 'REQ_RES没有收到ACK';
            case 0x05: return 'PING没有收到PONG';
            case 0x06: return 'FLASH错误';
            case 0x07: return 'FLASH超时';
            case 0x08: return 'STORE校验失败';
            case 0x09: return 'OTA ID错误';
            case 0x0A: return 'OTA PKG错误';
            case 0x0B: return 'OTA MD5校验和错误';
        }
        return `未知错误:${src}-${ec}`;
    }
    switch (src) {
        case addr.MAIN: return main_err_info(ec); break
        case addr.HEAT: return heat_err_info(ec); break
        case addr.WEIGHT: return weight_err_info(ec); break
    }

    return `未知控制板错误信息:${src}-${ec}`;
}


export function errMsg(ec: number) {
    switch (ec) {
        case 0: return '正常';
        case 0x01: return '无效的参数';
        case 0x02: return '参数解析错误';
        case 0x03: return 'SESSION没有收到ACK';
        case 0x04: return 'REQ_RES没有收到ACK';
        case 0x05: return 'PING没有收到PONG';
        case 0x06: return 'FLASH错误';
        case 0x07: return 'FLASH超时';
        case 0x08: return 'STORE校验失败';
        case 0x09: return 'OTA ID错误';
        case 0x0A: return 'OTA PKG错误';
        case 0x0B: return 'OTA MD5校验和错误';
    }
    return `未知错误:${ec}`;
}


function main_action(action: number) {
    switch (action) {
        case 0: return '复位';
        case 1: return '发送指令煮面前清洗';
        case 2: return '旋转到对应的列';
        case 3: return '升降到对应的行';
        case 4: return '机械臂取货';
        case 5: return '等待旋转完成';
        case 6: return '升降上升取货';
        case 7: return '机械臂把货拿出来';
        case 8: return '旋转避位';
        case 9: return '升降到保温门';
        case 10: return '保温门打开';
        case 11: return '升降到保温门等待';
        case 12: return '机械臂转出来';
        case 13: return '煮面室内门打开';
        case 14: return '外推货后退';
        case 15: return '升降下降放下货物';
        case 16: return '保温门关闭';
        case 17: return '外推货前进';
        case 18: return '。。。';
        case 19: return '发送指令煮面';
        case 20: return '机械臂初始化';
        case 21: return '升降初始化';
        case 22: return '旋转初始化';
        case 23: return '煮面室内门关闭';
        case 24: return '升降等待';
        case 25: return '...';
        case 26: return '取物门打开';
        case 27: return '取物门关闭';
        case 28: return '发送指令煮面后清洗';
    }
    return `未知动作:${action}`;
}

function heat_action(action: number) {
    switch (action) {
        case 0: return '运动到C';
        case 1: return '清洗放水';
        case 2: return '清洗蒸汽';
        case 3: return '喷嘴回零点';
        case 4: return '运动到K';
        case 5: return '预放水';
        case 6: return '解冻';
        case 7: return '运动到E';
        case 8: return '放水';
        case 9: return '运动到H';
        case 10: return '搅拌';
        case 11: return '运动到I';
        case 12: return '防阻塞';
    }

    return `未知动作:${action}`;
}

export function main_action_msg(action: number, ec: number) {
    return `${main_action(action)}:${err_msg_info(addr.MAIN, ec)}`;
}

export function heat_action_msg(action: number, ec: number) {
    return `${heat_action(action)}:${err_msg_info(addr.HEAT, ec)}`;
}

